﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Web;

namespace ExtraClub.Domain.Framework {
    public class SiteContext {
        private static readonly string key = "SITE_CONTEXT_PER_HTTPCONTEXT";
        public static ISiteContext Current {
            [DebuggerStepThrough]
            get {
                HttpContext httpContext = HttpContext.Current;
                if (httpContext == null) throw new ApplicationException("Application must run in HTTP environment.");

                ISiteContext context = httpContext.Items[key] as ISiteContext;

                if (context == null) {
                    context = new SiteContextInstance(httpContext); 
                    httpContext.Items[key] = context;
                }
                return context;
            }
        }
    }
}
